rm(list = ls())
options(warn=-1)
library(rgl)
library(misc3d)
knitr::knit_hooks$set(webgl = hook_webgl)

Load plot3D functions.

source("./plot3D_func.R")

STitch3D’s spatial domain detection result reveals layer structures in cortex.

clusters <- c(1,2,5)
cluster_colors <- c('#ff7f0e','#2ca02c','#1f77b4')
um <- c(-0.03762093, -0.06319845, 0.997291744, 0,
        0.84057891, -0.54168296, -0.002617532, 0,
        0.54038119, 0.83820403, 0.073501527, 0,
        0, 0, 0, 1) # view2 #set the initial view of the 3D plot

plot3D_clusters(directory = "./res_mouse_brain",
                clusters = clusters,
                cluster_colors = cluster_colors,
                um = um)
#3D coordinates and model are based on CCFv3.
load("spotstable.RData")
load("VOLUMESMALL.RData")
load("VOLUME.RData")
cluster_df <- read.table(paste0("./res_mouse_brain/clustering_result.csv"), sep=",", header=TRUE)
colnames(cluster_df)[2] <- "cluster"
library(stringr)
cluster_df$X <- str_split_fixed(cluster_df$X, "-", 2)[, 1]
spots.table <- spots.table[cluster_df$X, ]
spots.table$X <- rownames(spots.table)
spots.table <- merge(spots.table, cluster_df, by=c("X"))
spots.table$cluster <- as.integer(spots.table$cluster)
um <- c(-0.6389505, -0.1887468, -0.7457324, 0,
        0.4022625, -0.9083022, -0.1147684, 0,
        -0.6556883, -0.3733116, 0.6562859, 0,
        0, 0, 0, 1)

open3d(windowRect = c(0, 0, 720, 720))
## glX 
##   3
par3d(persp)
## NULL
view3d(userMatrix = matrix(um, byrow=TRUE, nrow=4))
drawScene.rgl(list(VOLUMESMALL))

for (c in 1:length(clusters)){
  idx_cluster = (spots.table$cluster == clusters[c])
  spheres3d(spots.table[idx_cluster, ]$AP.paxTOallen - 530/2, 
           -spots.table[idx_cluster, ]$DV * 1000/25 - 320/2, 
           spots.table[idx_cluster, ]$ML * 1000/25, 
           col = cluster_colors[c], radius=5, 
           alpha=1)
}